/*
 * @Author: 晴鸢. 3013433857@qq.com
 * @Date: 2025-10-12 19:50:07
 * @LastEditors: 晴鸢. 3013433857@qq.com
 * @LastEditTime: 2025-10-15 14:23:24
 * @FilePath: /Learn/udp/main.cc
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
#include"UdpServer.hpp"
#include<memory>
#include<cstdio>
#include<vector>
void Usage(std::string proc)
{
    std::cout<<"\nUsage:"<<proc<<" port[1024+]\n"<<std::endl;
}
/*
//./udpserver port
std::string Hander(const std::string&str,const std::string &clientip,uint16_t clientport)
{
    std::cout<<"["<<clientip<<":"<<clientport<<"]#"<<str<<std::endl;
    std::string res="Server get a message:";
    res+=str;
    std::cout<<res<<std::endl;
    return res;
}

bool SafeCheck(const std::string &cmd)
{
    std::vector<std::string> key_word={
      "rm","mv","yum","kill","cp","uninstall","unlink"  
    };
    for(auto d:key_word)
    {
        auto pos=cmd.find(d);
        if(pos!=std::string::npos)
        {
            return false;
        }
    }
    return true;
}

//模拟xshell执行指令的场景
std::string ExcuteCommand(const std::string&cmd)
{
    if(!SafeCheck(cmd)) return "error";
    FILE*fp=popen(cmd.c_str(),"r");
    if(fp==nullptr)
    {
        perror("popen");
        return "error";
    }
    std::string result;
    char buffer[4096];
    while(true)
    {
        char*res=fgets(buffer,sizeof(buffer),fp);
        if(res==nullptr) break;
        result+=res;
    }
    pclose(fp);
    return result;
}
*/
int main(int argc,char*argv[])
{
    if(argc!=2)
    {
        Usage(argv[0]);
        exit(0);
    }
    uint16_t port=std::stoi(argv[1]);
    //"192.168.232.200"
    std::unique_ptr<UdpServer> svr(new UdpServer(port,"192.168.232.200"));
    svr->Init();
    //svr->Run(Hander);
    svr->Run();
    return 0;
}